package com.caregiver.watch.business.user.model.po;

import com.caregiver.watch.business.user.enums.WeekDay;
import com.caregiver.watch.business.user.utils.reminder.RepeatDaysMaskUtil;
import lombok.Data;

import java.time.LocalTime;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;

@Data
public class UserAlarmClockConfig {
    private Long id;
    private Long userId;
    /**
     * 闹钟时间
     */
    private LocalTime alarmTime;
    /**
     * 重复周期
     */
    private Integer repeatDays;
    /**
     * 是否启用
     */
    private Integer isEnabled;
    private LocalDateTime createdTime;
    private LocalDateTime updatedTime;
    private Integer delFlag;

    /**
     * 获取重复的星期集合
     * @return 星期集合
     */
    public Set<WeekDay> getRepeatDaysSet() {
        if (this.repeatDays == null) {
            return new HashSet<>();
        }
        return RepeatDaysMaskUtil.fromMaskValue(this.repeatDays);
    }

    /**
     * 设置重复的星期集合
     * @param days 星期集合
     */
    public void setRepeatDaysSet(Set<WeekDay> days) {
        this.repeatDays = RepeatDaysMaskUtil.toMaskValue(days);
    }

    /**
     * 检查是否在指定星期重复
     * @param day 星期
     * @return 是否重复
     */
    public boolean isRepeatOn(WeekDay day) {
        if (this.repeatDays == null) {
            return false;
        }
        return RepeatDaysMaskUtil.contains(this.repeatDays, day);
    }

    /**
     * 添加重复星期
     * @param day 星期
     */
    public void addRepeatDay(WeekDay day) {
        if (this.repeatDays == null) {
            this.repeatDays = 0;
        }
        this.repeatDays = RepeatDaysMaskUtil.addDay(this.repeatDays, day);
    }

    /**
     * 移除重复星期
     * @param day 星期
     */
    public void removeRepeatDay(WeekDay day) {
        if (this.repeatDays != null) {
            this.repeatDays = RepeatDaysMaskUtil.removeDay(this.repeatDays, day);
        }
    }
}
